import { uploadToBackblazeB2 } from '../cli/utils/upload.js';
import { request, requestStream } from './client.js';

async function createDeployment(options) {
  const { bearerToken } = options;
  return request("/deploy", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${bearerToken}`
    }
  });
}
function streamDeployment(options, callback) {
  const { deploymentId, signature } = options;
  return requestStream(`/deploy-stream/${deploymentId}?signature=${signature}`, callback);
}
async function updateDeployment(options) {
  const { bearerToken, deployId, event } = options;
  return request(`/deploy/${deployId}`, {
    method: "PUT",
    headers: {
      Authorization: `Bearer ${bearerToken}`
    },
    body: { event }
  });
}
async function uploadBundle(options) {
  const { bundlePath, uploadKey, uploadToken, uploadUrl } = options;
  await uploadToBackblazeB2(uploadUrl, uploadToken, bundlePath, uploadKey);
}

export { createDeployment, streamDeployment, updateDeployment, uploadBundle };
